﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;

namespace GloberoSport.Datos
{
    public class TrackPoint
    {
        public static DataTable buscar(int iTrackId, int iTrackPointIndice)
        {
            dbManager db = new dbManager();
            db.Conectar();

            //PARAMETROS 
            object[] parametros = new object[4];
            parametros[0] = "@id";
            parametros[1] = iTrackId;
            parametros[2] = "@fecha";
            parametros[3] = iTrackPointIndice;
            return db.EjecutarSP_DS("TRACKPOINT_OBTENER", parametros).Tables[0];
        }

        public static DataTable buscar(int iTrackId)
        {
            dbManager db = new dbManager();
            db.Conectar();

            //PARAMETROS 
            object[] parametros = new object[2];
            parametros[0] = "@id";
            parametros[1] = iTrackId;
            return db.EjecutarSP_DS("TRACKPOINT_OBTENER", parametros).Tables[0];
        }

        public static int insertar(int trackid, int indice, decimal lat, decimal lon, decimal alt, decimal vel, DateTime fecha,
            decimal xOrigen, decimal xPrev, decimal tOrigen, decimal tPrev, decimal desnivel, string estado, int estadoCont)
        {
            int iRet = -1;
            object[] parametros = new object[28];
            parametros[0] = "@trackId";
            parametros[1] = trackid;
            parametros[2] = "@indice";
            parametros[3] = indice;
            parametros[4] = "@lat";
            parametros[5] = lat;
            parametros[6] = "@lon";
            parametros[7] = lon;
            parametros[8] = "@alt";
            parametros[9] = alt;
            parametros[10] = "@vel";
            parametros[11] = vel;
            parametros[12] = "@fecha";
            parametros[13] = fecha;
            parametros[14] = "@xOrigen";
            parametros[15] = xOrigen;
            parametros[16] = "@xPrev";
            parametros[17] = xPrev;
            parametros[18] = "@tOrigen";
            parametros[19] = tOrigen;
            parametros[20] = "@tPrev";
            parametros[21] = tPrev;
            parametros[22] = "@desnivel";
            parametros[23] = desnivel;
            parametros[24] = "@estado";
            parametros[25] = estado;
            parametros[26] = "@estadoCont";
            parametros[27] = estadoCont;

            dbManager db = new dbManager();
            db.Conectar();

            object salida = db.EjecutarSP("TRACK_POINT_INSERT", parametros);
            db.Desconectar();
            try
            {
                iRet = int.Parse(salida.ToString());
            }
            catch (Exception ex)
            {
                iRet = -10;
            }
            return iRet;
        }

    }
}

